package com.platform.controller.platform;

import com.platform.common.annotation.Log;
import com.platform.common.core.domain.AjaxResult;
import com.platform.common.core.page.TableDataInfo;
import com.platform.common.enums.BusinessType;
import com.platform.common.enums.ResultEnum;
import com.platform.common.exception.BusinessException;
import com.platform.system.domain.dto.device.AiUiConfigDto;
import com.platform.system.domain.dto.device.DeviceInfoDto;
import com.platform.system.domain.dto.device.FirmwareInfoDto;
import com.platform.system.domain.vo.device.DeviceInfoVo;
import com.platform.system.domain.vo.device.FirmwareInfoVo;
import com.platform.system.service.ISysFirmwareInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author Huangkai
 */
@Slf4j
@RestController
@RequestMapping("/device/firmwareInfo")
public class FirmwareInfoController {

    @Resource
    ISysFirmwareInfoService sysFirmwareInfoService;

    /**
     * 查询固件
     */
    @Log(title = "查询固件", businessType = BusinessType.OTHER)
    @GetMapping("/selectFirmwareInfoList")
    public TableDataInfo selectFirmwareInfoList(@Validated FirmwareInfoVo firmwareInfoVo) {
        return sysFirmwareInfoService.selectFirmwareInfoList(firmwareInfoVo);
    }

    /**
     * 查询详情
     */
    @Log(title = "查询详情", businessType = BusinessType.OTHER)
    @GetMapping("/selectFirmwareInfo/{uid}")
    public AjaxResult selectFirmwareInfo(@PathVariable(value = "uid") String uid) {
        FirmwareInfoDto firmwareInfoDto = sysFirmwareInfoService.selectFirmwareInfo(uid);
        if(firmwareInfoDto == null){
            throw new BusinessException(ResultEnum.DATA_NOT_EXIST);
        }
        return AjaxResult.success(firmwareInfoDto);
    }

    /**
     * 插入
     */
    @Log(title = "插入", businessType = BusinessType.UPDATE)
    @PostMapping("/insertFirmwareInfo")
    public AjaxResult insertFirmwareInfo(@RequestBody @Validated FirmwareInfoVo firmwareInfoVo) {
        return sysFirmwareInfoService.insertFirmwareInfo(firmwareInfoVo);
    }

    /**
     * 修改
     */
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PostMapping("/updateFirmwareInfo")
    public AjaxResult updateFirmwareInfo(@RequestBody @Validated FirmwareInfoVo firmwareInfoVo) {
        return sysFirmwareInfoService.updateFirmwareInfo(firmwareInfoVo);
    }


    /**
     * 删除
     */
    @Log(title = "删除", businessType = BusinessType.DELETE)
    @PostMapping("/delFirmwareInfo")
    public AjaxResult delFirmwareInfo(@RequestBody @Validated FirmwareInfoVo firmwareInfoVo) {
        return sysFirmwareInfoService.delFirmwareInfo(firmwareInfoVo);
    }
}
